package net.tngou.iask.service;

import java.util.List;

import net.tngou.iask.dao.AdviceDao;
import net.tngou.iask.jdbc.PageUtil;
import net.tngou.iask.pojo.Access;
import net.tngou.iask.pojo.Advice;
import net.tngou.iask.util.StringUtil;

/**
 * 问卷建议
 * @author tngou@tngou.net
 *
 */
public class AdviceService extends BaseService {
	/**
	 * 取得访问的建议
	 * @param access
	 * @return
	 */
	public List<Advice> getAdvice(long access) {
		AdviceDao dao = new AdviceDao();
		return dao.getAdvice(access);
	}
	
	/**
	 * 
	 * @param access
	 * @return
	 */
	public void setAdvice(Access access) {
		String advice="";
		float score=100;
		List<Advice> list= getAdvice(access.getId());
		for (Advice e : list) {
			advice=advice+e.getDescription()+"<br>";
			score=score-e.getScore();
		}
		if(StringUtil.isEmpty(advice))advice="目前身体健康正常，请保持良好的生活习惯于作息时间！"+"<br>";
		access.setAdvice(advice);
		access.setScore(score);
		access.update();
		
	}
	
	/**
	 * 
	 * @param page
	 * @param size
	 * @param main
	 * @param keyword
	 * @return
	 */
	public PageUtil getPage(int page,int size,long main,String keyword) {
		AdviceDao dao = new AdviceDao();
		return dao.getPage(page, size, main, keyword);
				
	}
}
